package com.lianyi.login.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.DefaultAdapter;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import com.lianyi.commonsdk.core.RouterHub;
import com.lianyi.login.di.component.DaggerDoctorListComponent;
import com.lianyi.login.di.module.DoctorListModule;
import com.lianyi.login.mvp.contract.DoctorListContract;
import com.lianyi.login.mvp.presenter.DoctorListPresenter;
import com.lianyi.module_login.R;
import com.lianyi.module_login.R2;


import javax.inject.Inject;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

@Route(path = RouterHub.LOGIN_DOCTORLISTACTIVITY)
public class DoctorListActivity extends BaseActivity<DoctorListPresenter> implements DoctorListContract.View {

    public static final String DOCTOR_LIST_ALL = "DOCTOR_LIST_ALL";
    @BindView(R2.id.recyclerView)
    RecyclerView mRecyclerView;
    @Inject
    RecyclerView.LayoutManager mLayoutManager;
    @Inject
    RecyclerView.Adapter mAdapter;

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerDoctorListComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .doctorListModule(new DoctorListModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.login_activity_doctor_list; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        initRecyclerView();
        Bundle bundle = getIntent().getExtras();
        mPresenter.getDoctorList(bundle);
    }

    /**
     * 初始化RecyclerView
     */
    private void initRecyclerView() {
        ArmsUtils.configRecyclerView(mRecyclerView, mLayoutManager);
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    public Activity getActivity() {
        return this;
    }


    @Override
    protected void onDestroy() {
        DefaultAdapter.releaseAllHolder(mRecyclerView);//super.onDestroy()之后会unbind,所有view被置为null,所以必须在之前调用
        super.onDestroy();
    }
}
